package com.changzhi.controller;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.changzhi.common.util.Result;
import com.changzhi.common.util.SignUtils;
import com.changzhi.common.util.TokenUtil;
import com.changzhi.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:测试
 * @author: 小落
 * @date: 2020年10月10日
 */
@Slf4j
@RestController
@RequestMapping("redis")
public class TestRedisController {

	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private RedisTemplate redisTemplate;

	public int num = 0;


	@PostMapping("test")
	public Object test(@RequestBody Map<String,Object> map){
		return "ok";
	}


	public static void main(String[] args) {
		String url = "https://api.xbyy.live/rest/channel/real_time_info";
		String[] arr = getArr();
		//请求api

		for (String userId : arr) {
			Map<String, Object> params = new HashMap<>();
			params.put("channelId", "1296383693459292161");
			params.put("ownerId", "1304681972085293056");
			//		params.put("familyId", );
			params.put("timestamp", System.currentTimeMillis()/1000);
			params.put("version", 3);
			params.put("os", 0);
			params.put("appVersion", "3.0.8");
			params.put("token", TokenUtil.createToken(userId, 72));
			String requestBody = JSON.toJSONString(params);
			new Thread(()->{
				HttpRequest request = HttpRequest.post(url).header("sign", SignUtils.sign(params)).body(requestBody);
				String response = request.execute().body();
				log.warn("response={}",response);
				Result result = JSON.parseObject(response, Result.class);
				if(result.getCode() != 0){
					log.error("response={}",response);
				}
			}).start();
		}
	}

	private static String[] getArr(){
		String[] arr = new String[]{
				"1201833284657479680",
				"1202070665255976960",
				"1202135070047993856",
				"1202146726958333952",
				"1202147085546160128",
				"1202455197746462720",
				"1202474603595694080",
				"1202521496887492608",
				"1202540948685324288",
				"1202545863742717952",
				"1202611081164357632",
				"1202655496033533952",
				"1202798624052871168",
				"1202825484975472640",
				"1202825931920506880",
				"1202844026059882496",
				"1202853421971931136",
				"1202855619195830272",
				"1202880849205264384",
				"1202881454686601216",
				"1202889699127984128",
				"1202902120072740864",
				"1202940210006982656",
				"1202942299948974080",
				"1202946971438940160",
				"1203334254117781504",
				"1203872538678001664",
				"1203911069072883712",
				"1203923806217830400",
				"1203939887187755008",
				"1203952293108514816",
				"1203952570226180096",
				"1203955122699239424",
				"1203959010823241728",
				"1204032486242254848",
				"1204244635233288192",
				"1204300922449035264",
				"1204330511980298240",
				"1204532497166106624",
				"1204657704665088000",
				"1204685684409892864",
				"1204730731457150976",
				"1204734780252356608",
				"1204745620623982592",
				"1204949223049527296",
				"1204964574579654656",
				"1205022537705062400",
				"1205025081923731456",
				"1205025425902796800",
				"1205031453826482176",
				"1205056466340282368",
				"1205058937510952960",
				"1205328972611584000",
				"1205364846518861824",
				"1205406177387610112",
				"1205410275688185856",
				"1205416617605857280",
				"1205417312870465536",
				"1205442132467253248",
				"1205448676818812928",
				"1205455495708540928",
				"1205457859744104448",
				"1205461479940161536",
				"1205463349899296768",
				"1205465354415898624",
				"1205475714120286208",
				"1205477116120924160",
				"1205480769204518912",
				"1205481066362568704",
				"1205493733768822784",
				"1205497721696288768",
				"1205514700486344704",
				"1205535266484256768",
				"1205539663595438080",
				"1205552278782607360",
				"1205583039833309184",
				"1205620833049903104",
				"1205648222182178816",
				"1205660639800852480",
				"1205660765910990848",
				"1205661054965645312",
				"1205666035143802880",
				"1205667435605131264",
				"1205668081959960576",
				"1205670241829388288",
				"1205672741034786816",
				"1205672973336313856",
				"1205676344952750080",
				"1205678771064012800",
				"1205681345964015616",
				"1205684420812472320",
				"1205687136141967360",
				"1205692059285979136",
				"1205693833858252800",
				"1205699532482936832",
				"1205709147023081472",
				"1205710597400821760",
				"1205716437641986048",
				"1205717474759147520",
				"1205721044342538240",
		};
		return arr;
	}


}
